package com.javase.objectclone;

/**
 * @Auther: liyanhao
 * @Description: 深复制
 * @Date: 2022/5/18 13:08
 * @Version: v1.0
 */
public class Student {
    String name;
    int age;
    Professor p;

    public Student(String name, int age, Professor p) {
        this.name = name;
        this.age = age;
        this.p = p;
    }

    @Override
    public Student clone() throws CloneNotSupportedException {
        Student o = null;
        try {
            o = (Student)super.clone();
        }catch (Exception e){
            System.out.println(e.toString());
            e.printStackTrace();
        }
        o.p = (Professor) p.clone();
        return o;
    }
}

class Professor{
    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
